
#include "dev_off_line.h"
#include "../res/img_common.h"
#include "pt_fs.h"
#include "sys_font.h"



int ui_dev_off_line_create(lv_obj_t* parent,ui_dev_off_line_t* dev_off_line)
{
    dev_off_line->bg_img = lv_img_create(parent);
    #if 0
    lv_img_set_src(dev_off_line->bg_img,pt_fs_get("BG_shutdown.png"));
    #else
    lv_img_set_src(dev_off_line->bg_img,&BG_shutdown);
    #endif
    lv_obj_set_pos(dev_off_line->bg_img,0,0);
    //***************************************************************************
    dev_off_line->title = lv_label_create(parent);
    lv_obj_set_pos(dev_off_line->title,94,115);
    lv_obj_set_size(dev_off_line->title,264,70);
    lv_obj_set_style_text_align(dev_off_line->title,LV_TEXT_ALIGN_CENTER,0);
    lv_obj_set_style_text_opa(dev_off_line->title,LV_OPA_80,LV_PART_MAIN);
    lv_obj_set_style_text_color(dev_off_line->title,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN); 
    lv_obj_set_style_text_font(dev_off_line->title, lv_font_get(60), LV_STATE_DEFAULT);
    lv_label_set_text( dev_off_line->title, "设备离线");
    //****************************************************************************
    dev_off_line->txt = lv_label_create(parent);
    lv_obj_set_pos(dev_off_line->txt,81,193);
    lv_obj_set_size(dev_off_line->txt,290,28);
    lv_obj_set_style_text_align(dev_off_line->txt,LV_TEXT_ALIGN_CENTER,0);
    lv_obj_set_style_text_opa(dev_off_line->txt,LV_OPA_40,LV_PART_MAIN);
    lv_obj_set_style_text_color(dev_off_line->txt,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN); 
    lv_obj_set_style_text_font(dev_off_line->txt, lv_font_get(20), LV_STATE_DEFAULT);
    lv_label_set_text( dev_off_line->txt, "请检查网络或者重新配网");
    //****************************************************************************

    return 0;
}

int ui_dev_off_line_destroy(ui_dev_off_line_t* dev_off_line)
{
    if(dev_off_line->bg_img){
        lv_obj_del(dev_off_line->bg_img);
        dev_off_line->bg_img = NULL;
    }
    if(dev_off_line->title){
        lv_obj_del(dev_off_line->title);
        dev_off_line->title = NULL;
    }
    if(dev_off_line->txt){
        lv_obj_del(dev_off_line->txt);
        dev_off_line->txt = NULL;
    }

    return 0;
}


int ui_dev_off_line_hide(ui_dev_off_line_t* dev_off_line)
{
    if(!dev_off_line){
        return -1;
    }

    if(dev_off_line->bg_img){
        lv_obj_add_flag(dev_off_line->bg_img,LV_OBJ_FLAG_HIDDEN);
    }
    if(dev_off_line->title){
        lv_obj_add_flag(dev_off_line->title,LV_OBJ_FLAG_HIDDEN);
    }
    if(dev_off_line->txt){
        lv_obj_add_flag(dev_off_line->txt,LV_OBJ_FLAG_HIDDEN);
    }

    return 0;
}

int ui_dev_off_line_show(ui_dev_off_line_t* dev_off_line)
{
    if(!dev_off_line){
        return -1;
    }

    if(dev_off_line->bg_img){
        lv_obj_clear_flag(dev_off_line->bg_img,LV_OBJ_FLAG_HIDDEN);
    }
    if(dev_off_line->title){
        lv_obj_clear_flag(dev_off_line->title,LV_OBJ_FLAG_HIDDEN);
    }
    if(dev_off_line->txt){
        lv_obj_clear_flag(dev_off_line->txt,LV_OBJ_FLAG_HIDDEN);
    }

    return 0;
}

